<template>
  <div class="app">
    <img class="bgone" src="../assets/login_bg.jpg" />
    <img class="pic" src="../assets/a.png" />
    <div class="table">
      <div class="wel">美团点餐后台管理系统</div>
      <div class="wel1">mei tuan dian can hou tai guan li xi tong</div>
      <!-- v-bind：model="绑定属性里面的值" -->
      <el-form ref="form" :model="user">
        <el-form-item>
          <el-input v-model="user.userName" placeholder="用户名" prefix-icon="el-icon-user-solid"></el-input>
        </el-form-item>
        <el-form-item>
          <el-input
            show-password
            v-model="user.passWord"
            placeholder="密码"
            prefix-icon="el-icon-lock"
          ></el-input>
        </el-form-item>
        <el-form-item>
          <el-button @click="login" type="primary">登录</el-button>
        </el-form-item>
      </el-form>
    </div>
  </div>
</template>

<script>
export default {
  // 里面放的是数据
  data() {
    return {
      user: {
        userName: "",
        passWord: ""
      }
    };
  },
  //  是vue的生命周期方法 new一个vue对象 在这里发起请求  请求服务器得到数据
  created() {},
  //  点击事件
  methods: {
    //  得到用户输入的数据  发起axsios请求
    login() {
      this.$ajax
        .post("http://localhost:8080/user/login", this.user)
        // 请求成功
        .then(res => {
          if (res.data.code == 200) {
            this.$message({
              message: "登录成功",
              type: "success"
            });
            console.log(res);
            // 把数据库里面的值存到页面上
            let storage = window.sessionStorage;
            storage.setItem("nickName",res.data.date.user.nickName);
            storage.setItem("avatar",res.data.date.user.avatar);
            // 跳转页面
            this.$router.push("/index")
          } else {
            this.user.userName = "";
            this.user.passWord = "";
            this.$message.error(res.data.message);
          }
        })
        .catch((err)=>{
          console.log(err);
          this.$message.error("连接超时请检查网络");
        });
    },
  },
};
</script>
<style scoped>
.home {
  width: 100%;
  height: 100%;
}
.wel {
  width: 960px;
  height: 35px;
  color: #fff;
  font-size: 30px;
  position: absolute;
  top: -7rem;
  text-align: center;
}
.wel1 {
  width: 960px;
  height: 35px;
  color: #fff;
  font-size: 12.38px;
  position: absolute;
  top: -4rem;
  text-align: center;
}

.bgone {
  width: 100%;
  height: 100%;
}
.table {
  background-color: #ffffff;
  width: 960px;
  height: 465px;
  position: absolute;
  top: 20%;
  right: 0;
  left: 0;
  bottom: 0;
  margin: auto;
  box-shadow: 10px 10px 5px #888888;
}
.table >>> .el-form {
  position: absolute;
  top: 7.8rem;
  right: 4rem;
}
.pic {
  width: 492px;
  height: auto;
  position: absolute;
  top: 173px;
  right: 453px;
  left: 0;
  bottom: 0;
  margin: auto;
  z-index: 99999;
}
.el-input >>> .el-input__inner {
  width: 373px;
  height: 55px;
}
.el-form-item >>> .el-button {
  width: 373px;
  font-size: 20px;
}
</style>

